use 	"./output/cities_expandedpatents", clear

** PREP **
gen		longnpis = (days_npis>=90) if !mi(days_npis) // Natural break in data, about 61% have short

egen	idxm = group(gen_id f_m)
gen		logpat_wtd = ln(pat_wtd_inv)

** PLOT OPTIONS **
set scheme plotplainblind

** Figure 1 **

{
	keep if (f_myr>=tm(1916m1)) & (f_myr<=tm(1921m1))
	
	// take out fixed effects
	reghdfe logpat_wtd, absorb(idxm) residuals(logpat_wtd_wo_fe)

	// collapse and set
	collapse (mean) logpat_wtd_wo_fe, by(longnpis f_myr)
	tsset longnpis f_myr
	
	local lw1 = 0.25
	local lw2 = 0.5
	
		** PLOTTING **
		twoway (tsline logpat_wtd_wo_fe if longnpis == 1, lcolor(blue%60) lwidth(`lw1') lpattern(dash)) || ///
			(tsline logpat_wtd_wo_fe if longnpis == 0, lcolor(orange%60) lwidth(`lw1') lpattern(dash)) || ///
			(lpoly	logpat_wtd_wo_fe f_myr if longnpis == 1, lcolor(blue) bw(1.5) lwidth(`lw2') lpattern(solid)) || ///
			(lpoly	logpat_wtd_wo_fe f_myr if longnpis == 0, lcolor(orange) bw(1.5) lwidth(`lw2') lpattern(solid)) || ///
			(scatteri -0.1 -508.5 -0.56 -508.5, recast(line) lcolor(gs7) lpattern(dot)) || ///
			(scatteri 0.5 -496.5 -0.565 -496.5, recast(line) lcolor(gs2) lpattern(dot)) || ///
			(scatteri -0.1 -490.5 -0.56 -490.5, recast(line) lcolor(gs7) lpattern(dot)), ///
			ytitle("Mean Log Residual Patenting Rate") xtitle("") xlabel(, nogrid) ylabel(, nogrid) ///
			text(-0.52 -516.5 "Before", c(gs8)) ///
			text(-0.52 -502.5 "Baseline", c(gs8)) ///
			text(-0.52 -493.5 "During", c(gs8)) ///
			text(-0.52 -482.5 "After", c(gs8)) ///
			text(0.48 -498.5 "Pre", c(gs8)) ///
			text(0.48 -494 "Post", c(gs8)) ///
			text(0.48 -502 "`=ustrunescape("\u2190")'", c(gs8)) ///
			text(0.48 -490.5 "`=ustrunescape("\u2192")'", c(gs8)) ///
			legend(pos(6) row(2) order(1 "Long NPI (>90 Days) Cities" 3 "(smoothed)" 2 "Short NPI (<90 Days) Cities" 4 "(smoothed)"))
						
	graph export "$RES/Figure1.png", replace
}
